package so.wy.servicecenter.businessbed.manager.normal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import so.wy.servicecenter.base.frame.manager.AbstractManager;
import so.wy.servicecenter.businessbed.dao.enums.StatusUserDepositEnum;
import so.wy.servicecenter.businessbed.dao.rdb.rent_user.RentUserDAO;
import so.wy.servicecenter.businessbed.dao.rdb.rent_user.RentUserDO;

import java.math.BigDecimal;
import java.util.Date;

@Service
@Scope("prototype")
public class RentUserNManager extends AbstractManager {
    @Autowired
    private RentUserDAO rentUserDAO;

    //押金支付结果
    public void yjPayResult(boolean success, Long rentUserId, BigDecimal fee) {
        RentUserDO rentUserDO = rentUserDAO.selectById(rentUserId);

        if (success) {
            rentUserDO.setDepositAmount(rentUserDO.getDepositAmount().add(fee));
            rentUserDO.setDepositStatus(StatusUserDepositEnum.PAYD.getCode());
            rentUserDO.setDepositTime(new Date());
            rentUserDAO.updateById(rentUserDO);
        }
    }

    //押金提取结果
    public void yjTqResult(boolean success, Long rentUserId, BigDecimal fee) {
        RentUserDO rentUserDO = rentUserDAO.selectById(rentUserId);

        if (success) {
            BigDecimal balance = rentUserDO.getDepositAmount().subtract(fee);
            rentUserDO.setDepositAmount(balance);
            rentUserDO.setDepositStatus(balance.compareTo(new BigDecimal(0)) == 1 ? StatusUserDepositEnum.PAYD.getCode() : StatusUserDepositEnum.NOTPAYD.getCode());
            rentUserDAO.updateById(rentUserDO);
        }
    }
}
